import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectionExample {
    public static void main(String[] args) {
        if (args.length < 1) {
            System.out.println("请提供一个类名作为参数。");
            return;
        }

        String className = args[0];

        try {
            // 加载类
            Class<?> clazz = Class.forName(className);

            // 打印类名
            System.out.println("类名: " + clazz.getName());

            // 打印类上的注解
            System.out.println("\n类上的注解:");
            Annotation[] classAnnotations = clazz.getDeclaredAnnotations();
            for (Annotation annotation : classAnnotations) {
                System.out.println("注解类型: " + annotation.annotationType().getName());
            }

            // 打印所有公共方法
            System.out.println("\n方法:");
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                System.out.println("方法名: " + method.getName());
                System.out.println("返回类型: " + method.getReturnType().getName());

                // 打印方法上的注解
                Annotation[] methodAnnotations = method.getDeclaredAnnotations();
                if (methodAnnotations.length > 0) {
                    System.out.println("方法上的注解:");
                    for (Annotation annotation : methodAnnotations) {
                        System.out.println("  注解类型: " + annotation.annotationType().getName());
                    }
                }

                // 打印方法参数类型
                System.out.println("参数类型:");
                Class<?>[] parameterTypes = method.getParameterTypes();
                for (Class<?> paramType : parameterTypes) {
                    System.out.println("  " + paramType.getName());
                }
                System.out.println();
            }

            // 打印所有公共字段
            System.out.println("\n字段:");
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                System.out.println("字段名: " + field.getName());
                System.out.println("字段类型: " + field.getType().getName());

                // 打印字段上的注解
                Annotation[] fieldAnnotations = field.getDeclaredAnnotations();
                if (fieldAnnotations.length > 0) {
                    System.out.println("字段上的注解:");
                    for (Annotation annotation : fieldAnnotations) {
                        System.out.println("  注解类型: " + annotation.annotationType().getName());
                    }
                }
                System.out.println();
            }

            // 打印所有公共构造器
            System.out.println("\n构造器:");
            Constructor<?>[] constructors = clazz.getDeclaredConstructors();
            for (Constructor<?> constructor : constructors) {
                System.out.println("构造器名: " + constructor.getName());

                // 打印构造器上的注解
                Annotation[] constructorAnnotations = constructor.getDeclaredAnnotations();
                if (constructorAnnotations.length > 0) {
                    System.out.println("构造器上的注解:");
                    for (Annotation annotation : constructorAnnotations) {
                        System.out.println("  注解类型: " + annotation.annotationType().getName());
                    }
                }

                // 打印构造器参数类型
                System.out.println("参数类型:");
                Class<?>[] paramTypes = constructor.getParameterTypes();
                for (Class<?> paramType : paramTypes) {
                    System.out.println("  " + paramType.getName());
                }
                System.out.println();
            }

        } catch (ClassNotFoundException e) {
            System.out.println("类 " + className + " 未找到。");
        }
    }
}